
package com.ruoyi.client.controller;


import com.ruoyi.client.pojo.vo.HomeCarouselVo;
import com.ruoyi.client.pojo.vo.HomeGoodsVo;
import com.ruoyi.client.pojo.vo.HomeInfoVo;
import com.ruoyi.client.service.HomeService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Anonymous //允许匿名访问
@CrossOrigin
@RestController("ClientHomeController")  //避免与后台管理的HomeController重名
@Api(value = "v1", tags = "01.首页模块")
@RequestMapping("home")
public class HomeController {

    @Resource
    private HomeService homeService;

    /**
     * 查询首页数据
     */
    @ApiOperation(value = "查询首页数据", notes = "轮播图、新品、推荐等")
    @GetMapping("/index")
    public R<HomeInfoVo> index() {  //熟悉Ruoyi框架的R对象 com.ruoyi.common.core.domain.R
        HomeInfoVo homeInfoVO = new HomeInfoVo();
        HashMap<String, Object> map = new HashMap<>();
        //首页轮播
        map.put("number", 4); //轮播记录数量
        map.put("typeId", 1); //1 轮播  / 2为你推荐  /3新品上线  /4热销商品
        List<HomeCarouselVo> carouselList = homeService.selectCarouselVoList(map);

        //首页为您推荐
        map.put("number", 6);//热销商品记录数量
        map.put("typeId", 2);//1 轮播  / 2为你推荐  /3新品上线  /4热销商品
        List<HomeGoodsVo> recommendGoodsList = homeService.selectGoodsVoList(map);

        //首页新品上线
        map.put("number", 6);//新品上线记录数量
        map.put("typeId", 3);//1 轮播  / 2为你推荐  /3新品上线  /4热销商品
        List<HomeGoodsVo> newGoodsList = homeService.selectGoodsVoList(map);

        //首页热销商品
        map.put("number", 6);//为您推荐记录数量
        map.put("typeId", 2);//1 轮播  / 2为你推荐  /3新品上线  /4热销商品
        List<HomeGoodsVo> hotGoodsList = homeService.selectGoodsVoList(map);

        homeInfoVO.setCarouselList(carouselList);
        homeInfoVO.setHotGoodsList(hotGoodsList);
        homeInfoVO.setNewGoodsList(newGoodsList);
        homeInfoVO.setRecommendGoodsList(recommendGoodsList);
        return R.ok(homeInfoVO);
    }
}
